package com.cloudkinto.enumType.address;

import com.baomidou.mybatisplus.core.enums.IEnum;
import com.cloudkinto.vo.common.CommonKvVo;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author long
 */
public enum AddressBookTypeEnum implements IEnum<Integer> {

    /**
     *
     */
    zero(0, "仓库地址"),
    one(1, "FAB仓库地址"),
    two(2, "退件地址"),
    three(3, "其他地址"),
    four(4, "经销商");

    private final int code;
    private final String desc;

    AddressBookTypeEnum(int code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    @Override
    public Integer getValue() {
        return code;
    }

    public static List<CommonKvVo> getAddressBookTypeList() {
        ArrayList<CommonKvVo> list = new ArrayList<>();
        for (AddressBookTypeEnum claimStatusEnum : values()) {
            list.add(
                    CommonKvVo.builder()
                            .label(claimStatusEnum.desc)
                            .value(claimStatusEnum.getValue())
                            .build()
            );
        }
        return list;
    }

    public static String getNameByValue(Integer value) {
        for (AddressBookTypeEnum claimStatusEnum : values()) {
            if (claimStatusEnum.getValue().equals(value)) {
                return claimStatusEnum.desc;
            }
        }
        return null;
    }

    public static Integer getValueByName(String name) {
        for (AddressBookTypeEnum claimStatusEnum : values()) {
            if (claimStatusEnum.desc.equals(name)) {
                return claimStatusEnum.getValue();
            }
        }
        return null;
    }

    public static List<Map<String, String>> getAddressBookEnumList() {
        List<Map<String, String>> list = new ArrayList<>();
        for (AddressBookTypeEnum addressBookTypeEnum : values()) {
            Map<String, String> map = new HashMap<>();
            map.put("nameCn", addressBookTypeEnum.desc);
            list.add(map);
        }
        return list;
    }
}
